<!-- 忘记密码 -->
<template>
    <div class="reset">
        <!-- 设置新密码 -->
        <transition name='page'>
            <div class="send" v-if="link==1">
                <div class='login-title clearfix'>
                    <span>设置新密码</span>
                    <p>请输入6-12位大小写字母、数字或字符</p>
                </div>
                <div class="login-input">
                    <input type="password" placeholder="请输入密码" v-model="password1"  maxlength="12">
                    <span class="clean"  v-show="password1!=''" @click="cleanClick()"></span>
                </div>
                <div :class="['login-btn shadow2',canNext ? 'can-login' :'']" @click="nextClick()">下一步</div>
            </div>
        </transition>
        <!-- 重复密码 -->
        <transition name='page'>
            <div class="check" v-if="link==2">
                <div class='login-title clearfix'>
                    <span>重复密码</span> 
                    <p>请输入6-12位大小写字母、数字或字符</p>
                </div>
                <div class="login-input clearfix">
                    <input type="password" placeholder="请输入密码" v-model="password2"  maxlength="12">
                    <span class="clean"  v-show="password2!=''" @click="cleanClick()"></span>
                </div>
                <div :class="['login-btn shadow2',canLogin ? 'can-login' :'']" @click="postReset()">确 定</div>
                <!-- <div :class="['login-btn',canLogin ? 'can-login shadow2' :'',{'waiting':waiting==1}]" @click="postReset()">
                    <span v-show="waiting==1"></span>
                </div> -->
            </div>
        </transition>
        <transition name='fadedown'>
            <Warning v-show="warnShow" :warnShow="warnShow" :warnText="warnText"></Warning>
        </transition>
    </div>
</template>

<script>
import Warning from '@/components/Warning'
import { axGet,axPost } from '@/api/index'
// import * as dd from 'dingtalk-jsapi'; //钉钉微应用

export default {
    name: "index",
    components:{
        Warning,
    },
    data(){
        return{
            setUserid:this.$route.query.userid, 
            isbak:this.$route.query.isbak,
            link:1,         //1遍密码，2遍密码
            phone:localStorage.getItem("readPhone") ? localStorage.getItem("readPhone") : '',  //电话
            password1:'',   //密码
            password2:'',   //密码
            checkNum:'',    //验证码
            checkValue:'',  //正确验证码
            canNext:false,  //下一步
            canLogin:false, //是否可登录
            waiting:0,
            timeLoop:{},    //计时器
            countdown:60,   //倒计时
            //提示窗
            warnShow:false,
            warnText:'',
        }
    },
    watch:{
        password1(newVal,oldVal){
            if(newVal){  
                let reguP=/^[1][3,4,5,6,7,8,9][0-9]{9}$/;  
                let reguW=/^[0-9a-zA-Z]*$/g;
                newVal.length>=6 && newVal.length<13 ? this.canNext=true : this.canNext=false;
            }
        },
        password2(newVal,oldVal){
            if(newVal){  
                newVal.length>=6 && newVal.length<13 ? this.canLogin=true : this.canLogin=false;
            }
        },
    },
    created(){ 
        this.$parent.menuShow=false; 
    },
    mounted(){
      
    },
    methods:{
        // 清除
        cleanClick(){
            if(this.link==1){
                this.password1='';
                this.canNext=false;
            }else if(this.link==2){
                this.password2='';
                this.canLogin=false;
            }
        },
        //下一步
        nextClick(){
            if(this.canNext){
                this.link=2
            }
        },
        //发送请求
        postReset(){
            if(this.canLogin && this.waiting!=1){
                this.waiting=1
                if(this.password1==this.password2){
                    axPost('ResetUserPassword', {
                        pass:this.password2,
                        cmd:'UserId',
                        userId: this.setUserid,
                        isbak:this.isbak,  
                    }).then(res => {
                        if(res.ResultCode==1){
                            this.$LayerTip({
                                content:"密码设置成功",
                                time:1000,
                            });
                            setTimeout(()=>{
                                this.$router.replace({path:'/login',query: {}});
                            },1000)
                        
                        }else{
                            this.warnShow=true
                            this.warnText='密码设置失败'
                        }
                        this.waiting=2
                    })
                }else{
                    this.warnShow=true
                    this.warnText='两次密码不同，请重新输入'
                    this.waiting=2
                }

            }
        },
        
    }
}
</script>